package com.t282.sale.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.t282.sale.pojo.Product;
import com.t282.sale.service.ProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Chen
 * @since 2021-05-19
 */
@Controller
@RequestMapping("/saleproduct")
public class ProductController {
    @Autowired
    private ProductService productService;

    @ResponseBody
    @RequestMapping ("/page2")
    @ApiOperation(value="获取所有分页信息")
    public Page PostListPage(@RequestParam(required = false,defaultValue = "1") int pageIndex,
                            @RequestParam(required = false) String prodName,
                            @RequestParam(required = false) String prodType,
                            @RequestParam(required = false) String prodBatch){
        Page<Product> page = new Page<>(pageIndex,5);
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();

        if(prodName!=null){
            queryWrapper.like("prod_name",prodName);
        }
        if(prodType!=null){
            queryWrapper.like("prod_type",prodType);
        }
        if(prodBatch!=null){
            queryWrapper.like("prod_batch",prodBatch);
        }

        Page<Product> page1 = productService.page(page,queryWrapper);
            return page1;
    }

}

